package com.stone.inventory.core.app.id;

import com.stone.inventory.core.domain.entity.StockLevel;
import com.stone.inventory.sharding.helper.ShardingHelper;
import com.stone.inventory.sharding.id.ShardingIdInjector;

/**
 * 库存分片ID注入器
 *
 * @author Mr_wenpan@163.com 2021/8/12 11:08 下午
 */
public class StockLevelShardingIdInjector implements ShardingIdInjector<String, StockLevel> {

    @Override
    public String getShardingData(StockLevel injectionObject) {
        // 这里使用posCode进行库存分片
        return injectionObject.getPosCode();
    }

    @Override
    public void injection(StockLevel injectionObject, Long id) {
        // 注入ID
        injectionObject.setStockLevelId(id);
    }

    @Override
    public String logicTableName() {

        return ShardingHelper.getEntityLogicTable(StockLevel.class);
    }
}